package cn.edu.wfit.modules.infomanagement.controller;

import java.util.List;

import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.web.page.TableDataInfo;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.modules.infomanagement.dto.TeacherReservationDetial;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.edu.wfit.modules.infomanagement.domain.TBusReservation;
import cn.edu.wfit.modules.infomanagement.service.ITBusReservationService;


/**
 * 存储教师预约记录Controller
 * 
 * @author zhanghao
 * @date 2025-11-07
 */
@RestController
@RequestMapping("/reservation")
public class TBusReservationController extends BaseController
{
    @Autowired
    private ITBusReservationService tBusReservationService;

    /**
     * 查询存储教师预约记录列表
     */
    @RequiresPermissions("system:reservation:list")
    @GetMapping("/list")
    public TableDataInfo list(TBusReservation tBusReservation)
    {
//        startPage();
        List<TBusReservation> list = tBusReservationService.selectTBusReservationList(tBusReservation);
        return getDataTable(list);
    }

    /**
     * 导出存储教师预约记录列表
     */
    @RequiresPermissions("system:reservation:export")
    @Log(title = "存储教师预约记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBusReservation tBusReservation)
    {
        List<TBusReservation> list = tBusReservationService.selectTBusReservationList(tBusReservation);
        ExcelUtil<TBusReservation> util = new ExcelUtil<TBusReservation>(TBusReservation.class);
        util.exportExcel(response, list, "存储教师预约记录数据");
    }

    /**
     * 获取存储教师预约记录详细信息
     */
    @RequiresPermissions("system:reservation:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tBusReservationService.selectTBusReservationById(id));
    }

    /**
     * 新增存储教师预约记录
     */
    @RequiresPermissions("system:reservation:add")
    @Log(title = "存储教师预约记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBusReservation tBusReservation)
    {
        return toAjax(tBusReservationService.insertTBusReservation(tBusReservation));
    }

    /**
     * 修改存储教师预约记录
     */
    @RequiresPermissions("system:reservation:edit")
    @Log(title = "存储教师预约记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBusReservation tBusReservation)
    {
        return toAjax(tBusReservationService.updateTBusReservation(tBusReservation));
    }

    /**
     * 删除存储教师预约记录
     */
    @RequiresPermissions("system:reservation:remove")
    @Log(title = "存储教师预约记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tBusReservationService.deleteTBusReservationByIds(ids));
    }

    /**根据工号和预约状态查询预约记录
     * @param tBusReservation 包含教师工号和预约状态的对象
     * @return 预约记录列表
     */
     @RequiresPermissions("system:reservation:query")
    @GetMapping("/queryByTeacherIdAndStatus")
    public AjaxResult queryByTeacherIdAndStatus(TBusReservation tBusReservation)
    {
        List<TeacherReservationDetial> teacherReservationDetials = tBusReservationService.selectTBusReservationListByTeacherIdAndStatus(tBusReservation);
        return success(teacherReservationDetials);
    }

    /**根据工号和预约dateId查询预约记录
     * @param tBusReservation 包含教师工号和预约dateId的对象
     * @return 预约记录
     */
    @RequiresPermissions("system:reservation:query")
    @GetMapping("/queryByTeacherIdAndDateId")
    public AjaxResult queryByTeacherIdAndDateId(TBusReservation tBusReservation)
    {
        TBusReservation tBusReservationDetail = tBusReservationService.selectTBusReservationByTeacherIdAndDateId(tBusReservation);
        return success(tBusReservationDetail);
    }
}
